import os,shutil
import mysql.connector

def query_style_names():
    mydb = mysql.connector.connect(host="192.168.10.81",user="hcecpod_com",passwd="Xcd9sMZ9DMBBkbMf",database="hcecpod_com")
    mycursor = mydb.cursor()
    mycursor.execute("select style_name,category from data_model group by style_name where hidden='yes' or hidden ='no'")
    myresult = mycursor.fetchall()
    name_list=[]
    num=0
    for x in myresult:
        name_list.append(x[0])
        path='Z:/系统/0-平铺细节图/'+str(x[0])
        if not os.path.exists(path):
            print('文件夹不存在：',x[1],x[0])
            mycursor.execute("update data_model set hidden='yes' where style_name=%s and hidden='no'",(x[0],))
            mydb.commit()
            print(mycursor.rowcount,"个数据被隐藏")
        else:
            file_list=os.listdir(path)
            if file_list==0:
                file_list
                # print('文件夹为空：',x[1],x[0])
            else:
                # print('文件夹存在：',x[1],x[0])
                mycursor.execute("update data_model set hidden='no' where style_name=%s and hidden='yes'",(x[0],))
                mydb.commit()
                num+=mycursor.rowcount
    print(num,"个数据被解除隐藏")
                
    mycursor.execute("update data_model set hidden='yes' where style_name='' or style_name is null and hidden='no'")
    mydb.commit()
    # print(mycursor.rowcount,"个数据被隐藏")

query_style_names()